<template>
	<view class="xkj">
		<view v-for="(item, index) in goodList" :key="index" class="goods-list">
			<view class="goods" @click="goGoodsDetail(item)">
				<u-image width="131rpx" height="131rpx" :src="item.image" border-radius="10" mode="aspectFit">
					<u-loading slot="loading"></u-loading>
				</u-image>
				<view class="goods-intro">
					<view>{{ item.goodsName }}</view>
					<view class="goods-sn">{{ item.goods_sn }}</view>
					<view>￥{{ item.price | unitPrice }}</view>
					<!-- <view style="display: flex;align-items: center;justify-content: space-between;">
						<view>￥{{ item.price | unitPrice }}</view>
						<view>
							<u-button @click="deleteGoodsCollectionFun(item)">移出选款架</u-button>
						</view>
					</view> -->

				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		getGoodsCollection,
		deleteGoodsCollection
	} from "@/api/members.js";

	export default {
		data() {
			return {
				goodList: [], //商品集合
				params: {
					pageNumber: 1,
					pageSize: 10,
				},
			}
		},
		onShow() {
			this.goodList = []
			this.getGoodList()
		},
		methods: {
			deleteGoodsCollectionFun(item) {
				deleteGoodsCollection(item.goodsId).then((res) => {
					if (res.statusCode == 200) {
						uni.showToast({
							title: "移除成功!",
							icon: "none",
						});
						this.goodList = []
						this.getGoodList()
					}
				});
			},
			goGoodsDetail(val) {
				//商品详情
				uni.navigateTo({
					url: "/pages/product/goods?id=" + val.skuId + "&goodsId=" + val.goodsId,
				});
			},
			getGoodList() {
				getGoodsCollection(this.params, "GOODS").then((res) => {
					if (res.data.success) {
						let data = res.data.result;
						if (data.total == 0) {
							this.goodsEmpty = true;
						} else if (data.total < 10) {
							this.goodsLoad = "noMore";
							this.goodList.push(...data.records);
						} else {
							this.goodList.push(...data.records);
							if (data.total.length < 10) this.goodsLoad = "noMore";
						}
					}
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.xkj {
		padding: 0 16rpx;
		width: 100vw;
		min-height: 100vh;
		background: #F3F5F9;
		// padding-top: 20rpx;
	}

	.goods {
		display: flex;
		align-items: center;
	}

	.goods-list {
		background: #fff;
		border-radius: 20rpx;
		margin: 20rpx 0;
		padding: 24rpx;
		// margin-bottom: 20rpx;
	}

	.goods-intro {
		flex: 1;
		font-size: $font-base;
		line-height: 48rpx;
		margin-left: 30rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		height: 131rpx;

		view:nth-child(1) {
			line-height: 1.4em;
			font-size: 24rpx;
			max-height: 2.8em; //height是line-height的整数倍，防止文字显示不全
			overflow: hidden;
			color: #666;
		}

		view:nth-child(2) {
			color: #cccccc;
			font-size: 24rpx;
		}

		view:nth-child(3) {
			color: $light-color;
		}
	}
</style>